{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcf_help.css?v={$version}"/>
<link rel="stylesheet" href="{__ADMIN_PATH}/pcf/template.css?v={$version}" media="all">
<script src="{__PUBLIC_PATH}/common/js/jquery.min.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-card-body" pad15>
                <div class="layui-form" wid100 lay-filter="">
                  <div class="layui-form-item">
                    <label class="layui-form-label">当前目录</label>
                    <div class="layui-input-inline">
                        <div style="padding:6px 0px;">
                            {$info['activepathname']|default=''}
                            <input type="hidden" name="activepath" value="{$info['activepath']|default=''}">
                        </div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">图片名</label>
                    <div class="layui-input-inline">
                        <div style="padding:6px 0px;">
                            {$info['filename']|default=''}
                            <input type="hidden" name="filename" value="{$info.filename|default=''}">
                        </div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">上传图片</label>
                    <div class="layui-input-inline" >
                        <input type="hidden" name="upfile" id="upfile" placeholder="图片地址" value="" lay-verify="check_upfile" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container layadmin-layer-demo" style="width:auto;padding:4px 0px;">
                        <button class="layui-btn test-upload-demoMore layui-btn-sm fl" lay-data="{number:1,ey_savepath:'allimg',ey_callback:'upfile_call'}"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                    </div>
                    <div class="none" style="padding:6px 0px;" id="upfile_filename">
                      <img src="" id="pcftup" style="width:300px;">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                    </div>
                  </div>
              </div>
            </div>
          </div>
      </div>
  </div>
</div>
{include file="public/footer"/}
<script>
  function upfile_call(imgObj) {
    $('#upfile').val(imgObj.url);
    $('#upfile_filename').show();
    var pcftup = document.getElementById('pcftup');
    pcftup.src = imgObj.url;
  }
  layui.use(['layer', 'form'], function () {
      var $ = layui.$,
      layer = layui.layer,
      form = layui.form;
      form.verify({
        check_upfile: function(value, item){
          if ($.trim(value) == '' || value == undefined || value == null) {
              return '请上传图片！';
          }
        }
      });
      //监听提交
      form.on('submit(formSubmit)', function(data){
          layer.load(2);
          $.ajax({
              type : 'post',
              url : "{:url('/channel.Filemanager/replace_img')}",
              data : data.field,
              dataType : 'json',
              success : function(res){
                  layer.closeAll();
                  layer.closeAll('loading');
                  if(res.status){
                      layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                          parent.location.href = res.url;
                      });
                  }else{
                      layer.msg(res.msg, {icon: 2, time: 1000});
                  }
              },
              error: function(e){
                  layer.closeAll('loading');
                  layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
              }
          });
          return false;
      });
  });
</script>
</body>
</html>